package com.cg.controller;

import com.cg.client.SystemClient;
import com.cg.dto.OrgPageDto;
import com.cg.dto.Result;
import com.cg.entity.Organize;
import com.cg.utils.TokenUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @ClassName OrganizeController
 * @Description TODO
 * @Author CG
 * @Date 2023/12/18 18:19
 **/
@RestController
@RequestMapping("/organize")
public class OrganizeController {

    @Resource
    private SystemClient systemClient;

    /**
     * 验证Code是否存在
     */
    @GetMapping("/queryCountByOrgCode")
    public Result queryCountByOrgCode(String orgName){
        return systemClient.queryCountByOrgCode(orgName);
    }

    /**
     * 新增组织编码
     */
    @PostMapping("/createOrganize")
    public Result createOrganize(HttpServletRequest request,Organize organize){
        String token = request.getHeader("token");
        Integer userId = TokenUtil.getUserIdByToken(token);
        organize.setCreateUser(userId);
        return systemClient.createOrganize(organize);
    }


    /**
     * 查询组织全部信息-分页并按照名称模糊查询
     */
    @PostMapping("/organizeList")
    public Result<Map<String,Object>> organizeList(OrgPageDto orgPageDto){
        return systemClient.organizeList(orgPageDto);
    }


    /**
     * 修改组织信息
     */
    @PostMapping("/setOrganize")
    public Result setOrganize(Organize organize){
        return systemClient.setOrganize(organize);
    }


    /**
     * 删除组织信息
     */
    @PostMapping("/removeOrganize")
    public Result removeOrganize(Integer id){
        return systemClient.removeOrganize(id);
    }

    /**
     * 查询组织详情
     */
    @PostMapping("/queryOrganizeByOrganizeId")
    public Result<Organize> queryOrganizeByOrganizeId(Integer organizeId){
        return systemClient.queryOrganizeByOrganizeId(organizeId);
    }
}
